package com.itheima.dubbo.web;

import com.itheima.dubbo.User;
import com.itheima.dubbo.UserInterface;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Version: V1.0
 * 1、如果相同的配置在提供方和消费方都同时配置，则消费方优于提供方
 */
@RestController
@RequestMapping("user")
public class UserController {


//    @DubboReference(timeout=5000)  // 远程调用
//    @DubboReference  // 远程调用
    @DubboReference(cluster = "failfast")  // 集群容错， 默认：failover 失败自动切换
//    @DubboReference(version = "1.0.1", check = false)  // 远程调用
    private UserInterface userInterface;


    @GetMapping("hello")
    public String hello(String username) {
        RpcContext.getContext().setAttachment("jwt", "ssfafw43242dgsd");
        String result = userInterface.hello(username);
        return result;
    }

    @GetMapping("findUser")
    public User findUser(String name) {
        User userVO = new User();
        userVO.setName(name);

        User user = userInterface.findUser(userVO);
        return user;

    }

}
